﻿using System.Threading;
using System;
using Silverlight.Training.Client.Common.ServiceReference.EventArgs;
using Silverlight.Training.Client.Common.ServiceReference.Interfaces;
using Silverlight.Training.Client.Common.ServiceReference.Contracts;
using System.ComponentModel;
using Silverlight.Training.Client.Common.ServiceReference.Feedbacks;

namespace Silverlight.Training.Client.Common.ServiceReference.Operations
{
    public partial class EMServiceClient
    {
        #region GetDepartmentCollection

        public event EventHandler<CollectionFeedbackCompletedEventArgs<Department>> GetDepartmentCollectionCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IEMService.BeginGetDepartmentCollection(AsyncCallback callback, object asyncState)
        {
            return base.Channel.BeginGetDepartmentCollection(callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        CollectionFeedback<Department> IEMService.EndGetDepartmentCollection(IAsyncResult result)
        {
            return base.Channel.EndGetDepartmentCollection(result);
        }

        private IAsyncResult OnBeginGetDepartmentCollection(object[] inValues, AsyncCallback callback, object asyncState)
        {
            return ((IEMService)(this)).BeginGetDepartmentCollection(callback, asyncState);
        }

        private object[] OnEndGetDepartmentCollection(IAsyncResult result)
        {
            CollectionFeedback<Department> retVal = ((IEMService)(this)).EndGetDepartmentCollection(result);
            return new object[] {
                retVal};
        }

        private void OnGetDepartmentCollectionCompleted(object state)
        {
            if ((this.GetDepartmentCollectionCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.GetDepartmentCollectionCompleted(this, new CollectionFeedbackCompletedEventArgs<Department>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetDepartmentCollectionAsync()
        {
            this.GetDepartmentCollectionAsync(null);
        }

        public void GetDepartmentCollectionAsync(object userState)
        {
            if ((this.onBeginGetDepartmentCollectionDelegate == null))
            {
                this.onBeginGetDepartmentCollectionDelegate = new BeginOperationDelegate(this.OnBeginGetDepartmentCollection);
            }
            if ((this.onEndGetDepartmentCollectionDelegate == null))
            {
                this.onEndGetDepartmentCollectionDelegate = new EndOperationDelegate(this.OnEndGetDepartmentCollection);
            }
            if ((this.onGetDepartmentCollectionCompletedDelegate == null))
            {
                this.onGetDepartmentCollectionCompletedDelegate = new SendOrPostCallback(this.OnGetDepartmentCollectionCompleted);
            }
            base.InvokeAsync(this.onBeginGetDepartmentCollectionDelegate, null, this.onEndGetDepartmentCollectionDelegate, this.onGetDepartmentCollectionCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetDepartmentCollectionDelegate;

        private EndOperationDelegate onEndGetDepartmentCollectionDelegate;

        private SendOrPostCallback onGetDepartmentCollectionCompletedDelegate;
        
        private partial class EMServiceClientChannel
        {
            public IAsyncResult BeginGetDepartmentCollection(AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[0];
                IAsyncResult _result = base.BeginInvoke("GetDepartmentCollection", _args, callback, asyncState);
                return _result;
            }

            public CollectionFeedback<Department> EndGetDepartmentCollection(IAsyncResult result)
            {
                object[] _args = new object[0];
                CollectionFeedback<Department> _result = ((CollectionFeedback<Department>)(base.EndInvoke("GetDepartmentCollection", _args, result)));
                return _result;
            }
        }

        #endregion

        #region GetSingleDepartment

        public event EventHandler<SingleFeedbackCompletedEventArgs<Department>> GetSingleDepartmentCompleted;

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        IAsyncResult IEMService.BeginGetSingleDepartment(int deptID, AsyncCallback callback, object asyncState)
        {
            return base.Channel.BeginGetSingleDepartment(deptID, callback, asyncState);
        }

        [EditorBrowsableAttribute(EditorBrowsableState.Advanced)]
        SingleFeedback<Department> IEMService.EndGetSingleDepartment(IAsyncResult result)
        {
            return base.Channel.EndGetSingleDepartment(result);
        }

        private IAsyncResult OnBeginGetSingleDepartment(object[] inValues, AsyncCallback callback, object asyncState)
        {
            int deptID = ((int)(inValues[0]));
            return ((IEMService)(this)).BeginGetSingleDepartment(deptID, callback, asyncState);
        }

        private object[] OnEndGetSingleDepartment(IAsyncResult result)
        {
            SingleFeedback<Department> retVal = ((IEMService)(this)).EndGetSingleDepartment(result);
            return new object[] {
                retVal};
        }

        private void OnGetSingleDepartmentCompleted(object state)
        {
            if ((this.GetSingleDepartmentCompleted != null))
            {
                InvokeAsyncCompletedEventArgs e = ((InvokeAsyncCompletedEventArgs)(state));
                this.GetSingleDepartmentCompleted(this, new SingleFeedbackCompletedEventArgs<Department>(e.Results, e.Error, e.Cancelled, e.UserState));
            }
        }

        public void GetSingleDepartmentAsync(int deptID)
        {
            this.GetSingleDepartmentAsync(deptID, null);
        }

        public void GetSingleDepartmentAsync(int deptID, object userState)
        {
            if ((this.onBeginGetSingleDepartmentDelegate == null))
            {
                this.onBeginGetSingleDepartmentDelegate = new BeginOperationDelegate(this.OnBeginGetSingleDepartment);
            }
            if ((this.onEndGetSingleDepartmentDelegate == null))
            {
                this.onEndGetSingleDepartmentDelegate = new EndOperationDelegate(this.OnEndGetSingleDepartment);
            }
            if ((this.onGetSingleDepartmentCompletedDelegate == null))
            {
                this.onGetSingleDepartmentCompletedDelegate = new SendOrPostCallback(this.OnGetSingleDepartmentCompleted);
            }
            base.InvokeAsync(this.onBeginGetSingleDepartmentDelegate, new object[] {
                    deptID}, this.onEndGetSingleDepartmentDelegate, this.onGetSingleDepartmentCompletedDelegate, userState);
        }

        private BeginOperationDelegate onBeginGetSingleDepartmentDelegate;

        private EndOperationDelegate onEndGetSingleDepartmentDelegate;

        private SendOrPostCallback onGetSingleDepartmentCompletedDelegate;

        private partial class EMServiceClientChannel
        {
            public IAsyncResult BeginGetSingleDepartment(int deptID, AsyncCallback callback, object asyncState)
            {
                object[] _args = new object[1];
                _args[0] = deptID;
                IAsyncResult _result = base.BeginInvoke("GetSingleDepartment", _args, callback, asyncState);
                return _result;
            }

            public SingleFeedback<Department> EndGetSingleDepartment(IAsyncResult result)
            {
                object[] _args = new object[0];
                SingleFeedback<Department> _result = ((SingleFeedback<Department>)(base.EndInvoke("GetSingleDepartment", _args, result)));
                return _result;
            }
        }

        #endregion
    }
}
